package com.freework.util.excel.read.service.rowToObject;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.PropertyUtils;

import com.freework.util.NumberUtil;
import com.freework.util.excel.read.vo.ColVO;
import com.freework.util.unmodifiableMap.KeysIndex;
import com.freework.util.unmodifiableMap.UnmodifiableKeyMap;

public class RowToMapImpi implements RowToObjectI {
	SetValueI[] setValue=null;
	KeysIndex keysIndex;
	public Object createObject() {
		return new UnmodifiableKeyMap(keysIndex);
	}
	public SetValueI[] getSetValues() {
		return setValue;
	}
	public void init(List<ColVO> list,Class clazz) {
		keysIndex=new KeysIndex();
		setValue =new SetValueI[list.size()];
		int i=0;
		for (ColVO colVO : list) {
			setValue[i]=new SetValue(i);
			keysIndex.setName(colVO.getColname());
			i++;
		}
	}
	class SetValue extends AbstractSetValue{
		int index=0;
		SetValue(int index){
			this.index=index;
			
		}
		public void setObjValue(Object obj, Object value, ColVO vo) {
			((UnmodifiableKeyMap)obj).putIndex(index, value);
		}

		Class getClass(ColVO vo) {
			return vo.getValueclazz()==null?String.class:vo.getValueclazz();
		}

		
	}

}
